<?php
       
class ManagerAction extends MY_Controller {
	
	function ManagerAction() {
		parent::My_Controller ();
	}
	
    /**
     * 具体工作人员安排与联系
     */
	function index() {
		$this->load->model('user/managermodel', 'managerModel', true);
		$user_id = $this->session->userdata ( 'user_id' );
		$data['manager_list'] = $this->managerModel->get_managers($user_id);
		$this->load->view("user/manager_index", $data);
	}
	
	function add() {
		$this->load->view('user/manager_add');
	}
	
	/**
	 * 加载数据
	 */
	function ajax_load() {
		$m_category = $this->input->post('m_category');
		$user_id = $this->session->userdata ( 'user_id' );
		$this->load->model('user/managermodel', 'managerModel', true);
		$data = $this->managerModel->get_manager($user_id, $m_category);
		if ($data) {
			$data['have_data'] = 1;
			
		} else {
			$data['have_data'] = 0;
		}
		echo json_encode($data);
	}
	
	/**
	 * ajax保存工作人员
	 */
	function ajax_save() {
		
		
		$this->load->library('form_validation');
		$this->form_validation->set_rules('name', '姓名', 'trim|required|max_length[5]|xss_clean');
		$this->form_validation->set_rules('phone', '电话', 'trim|max_length[20]|xss_clean');
		$this->form_validation->set_rules('remark', '备注', 'trim|max_length[50]|xss_clean');
		
		
		if ($this->form_validation->run() == FALSE) {
			$error = $this->form_validation->_error_array;
			$msg = "";
			foreach($error as $v) {
				$msg.=$v."\n";
			}
			echo $msg;
		} else {
			$this->load->model('user/managermodel', 'managerModel', true);
			$manager = $this->_form_data();
			$user_id = $this->session->userdata ( 'user_id' );
			$manager['user_id'] = $user_id;
			$this->managerModel->save_manager($manager);
			echo "1";
		}

	}
}

?>